package com.lebang.medicalInquiry.controller;



import com.lebang.medicalInquiry.constant.ResponseEnum;
import com.lebang.medicalInquiry.model.po.LanguageConfig;
import com.lebang.medicalInquiry.model.vo.PageVo;
import com.lebang.medicalInquiry.response.Callback;
import com.lebang.medicalInquiry.response.JsonData;
import com.lebang.medicalInquiry.service.LanguageConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequestMapping("/language/config")
@Api(tags = "语种配置")
@RestController
@Validated
public class LanguageConfigController {


    @Autowired
    private LanguageConfigService service;

    @GetMapping("/")
    @ApiOperation("")
    public JsonData list(HttpServletRequest request, HttpServletResponse response,
                         @ApiParam(name = "keyword", value = "关键词") @RequestParam(value = "keyword", required = false) String kw,
                         @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page,
                         @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit
                         ) {

        PageVo list = service.getList(kw,page,limit);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), list);

    }

    @PostMapping("/")
    @ApiOperation("")
    public JsonData operator(HttpServletRequest request, HttpServletResponse response
            , @RequestBody LanguageConfig po

    ) {


        service.operator(po);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }


    @DeleteMapping("/{id}")
    @ApiOperation("")
    public JsonData remove(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(name = "id", value = "id", required = true) @PathVariable Integer id

    ) {

        service.remove(id);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }

}